package com.hnyc.brand.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.hnyc.brand.domain.BrandOnline;
import com.hnyc.brand.service.IBrandOnlineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 品牌信息Controller
 * 
 * @author zero
 * @date 2023-03-10
 */
@RestController
@RequestMapping("/brand/brand")
public class BrandOnlineController extends BaseController
{
    @Autowired
    private IBrandOnlineService brandOnlineService;

    /**
     * 查询品牌信息列表
     */
    @PreAuthorize("@ss.hasPermi('brand:brand:list')")
    @GetMapping("/list")
    public TableDataInfo list(BrandOnline brandOnline)
    {
        startPage();
        List<BrandOnline> list = brandOnlineService.selectBrandOnlineList(brandOnline);
        return getDataTable(list);
    }

    /**
     * 导出品牌信息列表
     */
    @PreAuthorize("@ss.hasPermi('brand:brand:export')")
    @Log(title = "品牌信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BrandOnline brandOnline)
    {
        List<BrandOnline> list = brandOnlineService.selectBrandOnlineList(brandOnline);
        ExcelUtil<BrandOnline> util = new ExcelUtil<BrandOnline>(BrandOnline.class);
        util.exportExcel(response, list, "品牌信息数据");
    }

    /**
     * 获取品牌信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('brand:brand:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(brandOnlineService.selectBrandOnlineById(id));
    }

    /**
     * 新增品牌信息
     */
    @PreAuthorize("@ss.hasPermi('brand:brand:add')")
    @Log(title = "品牌信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BrandOnline brandOnline)
    {
        return toAjax(brandOnlineService.insertBrandOnline(brandOnline));
    }

    /**
     * 修改品牌信息
     */
    @PreAuthorize("@ss.hasPermi('brand:brand:edit')")
    @Log(title = "品牌信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BrandOnline brandOnline)
    {
        return toAjax(brandOnlineService.updateBrandOnline(brandOnline));
    }

    /**
     * 删除品牌信息
     */
    @PreAuthorize("@ss.hasPermi('brand:brand:remove')")
    @Log(title = "品牌信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(brandOnlineService.deleteBrandOnlineByIds(ids));
    }
}
